package laya.util;

public abstract class ProductCode
{
	public long PRODUCTID_MASK;
	public long VERSION_MASK;
	public long VERSUFF_MASK;
	public long BUILDNO_MASK;
	public long RELEASENO_MASK;
	public long CHECKCODE_MASK;
	public long COMPARE_MASK;
	
	long m_nProductID	= 0;
	long m_nVersion		= 0;
	long m_nVerSuff		= 0;
	long m_nBuildNo		= 0;
	long m_nReleaseType	= 0;
	long m_nCheckCode	= 0;
	
	public long getProductID()
	{
		return m_nProductID;
	}
	public void setProductID(long value)
	{
		m_nProductID = value;
	}
	public long getVersion()
	{
		return m_nVersion;
	}
	public void setVersion(long value)
	{
		m_nVersion = value;
	}
	public long getVerSuff()
	{
		return m_nVerSuff;
	}
	public void setVerSuff(long value)
	{
		m_nVerSuff = value;
	}
	public long getBuildNo()
	{
		return m_nBuildNo;
	}
	public void setBuildNo(long value)
	{
		m_nBuildNo = value;
	}
	public long getReleaseType()
	{
		return m_nReleaseType;
	}
	public void setReleaseType(long value)
	{
		m_nReleaseType = value;
	}
	public long getCheckCode()
	{
		return m_nCheckCode;
	}
	public void setCheckCode(long value)
	{
		m_nCheckCode = value;
	}
	
	public abstract long getCode();
	public abstract void setCode(long code);
	
	public boolean isValid()
	{
		return (makeCheckCode() == getCheckCode());
	}
	
	public abstract long makeCheckCode();
	public abstract String toHexString(long n);
	
	public String toString()
	{
		return 
			"ProductID: " + m_nProductID
			+ "\nVersion: " + m_nVersion
			+ "\nVersion suffix: " + m_nVerSuff
			+ "\nBuild number: " + m_nBuildNo
			+ "\nRelease type: " + m_nReleaseType
			+ "\nCheck code: " + m_nCheckCode
			+ "\n--------------------------------------------------"
			+ "\nProduct code: " + toHexString(getCode());
	}
	
	public static String getSubCode(String code, int begin, int end)
	{
		int count = end - begin + 1;
		begin = code.length() - begin - 1;
		end = code.length() - end - 1;
		
		if (0 > begin)
		{
			begin = end = 0;
		}
		else if (0 > end)
		{
			end = 0;
		}
		
		String result = code.substring(end , begin + 1);
		while (count != result.length())
		{
			result = '0' + result;
		}
		
		return result;
	}
}